package com.opencloud.iot.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotConfigs;
import com.opencloud.iot.provider.mapper.IotConfigsMapper;
import com.opencloud.iot.provider.service.IotCommonService;
import com.opencloud.iot.provider.service.IotConfigsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 进出记录操作
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotCommonServiceImpl implements IotCommonService {

    @Override
    public Long CreateMinTime(int timeValue, Date dateValue) {
        for(int i=1;i<=60/timeValue;i++)
        {
            int mm = timeValue*i;
            if(dateValue.getMinutes()<=mm)
            {
                dateValue.setMinutes((i-1)*timeValue+1);
                dateValue.setSeconds(0);
                break;
            }
        }
        return dateValue.getTime()/1000;
    }

    @Override
    public Long CreateMaxTime(int timeValue, Date dateValue) {

        for(int i=1;i<=60/timeValue;i++)
        {
            int mm = timeValue*(i-1);
            int nn = timeValue*i;
            if(dateValue.getMinutes()>=mm && dateValue.getMinutes()<=nn)
            {
                dateValue.setMinutes(i*timeValue);
                dateValue.setSeconds(59);
                if(i==60/timeValue-1){
                    dateValue.setHours(dateValue.getHours()+1);
                    dateValue.setMinutes(0);
                    dateValue.setSeconds(59);
                }
                break;
            }
        }
        return dateValue.getTime()/1000;
    }

}
